package com.example.travel_front.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.travel_front.R;
import com.example.travel_front.Model.Traveler;

import java.util.List;

public class NearbyTravelerAdapter extends RecyclerView.Adapter<NearbyTravelerAdapter.TravelerViewHolder> {
    private final List<Traveler> travelerList;

    public NearbyTravelerAdapter(List<Traveler> travelerList) {
        this.travelerList = travelerList;
    }

    @NonNull
    @Override
    public TravelerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_nearby_traveler, parent, false);
        return new TravelerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull TravelerViewHolder holder, int position) {
        Traveler traveler = travelerList.get(position);
        holder.txtName.setText(traveler.getName());
        holder.txtDiscoveries.setText(traveler.getDiscoveries() + " Discoveries");
        holder.txtLikes.setText(traveler.getLikes() + " likes");
        Glide.with(holder.imgAvatar.getContext()).load(traveler.getAvatarUrl()).error(R.drawable.ic_traveler_avatar).into(holder.imgAvatar);
    }

    @Override
    public int getItemCount() {
        return travelerList.size();
    }

    static class TravelerViewHolder extends RecyclerView.ViewHolder {
        ImageView imgAvatar;
        TextView txtName;
        TextView txtDiscoveries;
        TextView txtLikes;

        public TravelerViewHolder(@NonNull View itemView) {
            super(itemView);
            imgAvatar = itemView.findViewById(R.id.imgAvatar);
            txtName = itemView.findViewById(R.id.txtName);
            txtDiscoveries = itemView.findViewById(R.id.txtDiscoveries);
            txtLikes = itemView.findViewById(R.id.txtLikes);
        }
    }
}
